package com.yael.utils;

import java.util.Collections;

import net.sf.jsr107cache.Cache;
import net.sf.jsr107cache.CacheException;
import net.sf.jsr107cache.CacheManager;

public class CacheManagerService
{
	private static CacheManagerService instance = null;
	private Cache _cache = null;
	
	private CacheManagerService()
	{
		try
		{
			_cache = CacheManager.getInstance().getCacheFactory().createCache(Collections.emptyMap());
		}
		catch(CacheException e)
		{
			e.printStackTrace();
		}

	}
	
	public static CacheManagerService getInstance() {
		if (instance == null) {
			synchronized (CacheManagerService.class) {
				CacheManagerService cacheManagerService = instance;

				if (cacheManagerService == null) {
					synchronized (CacheManagerService.class) {
						instance = new CacheManagerService();
					}
				}
			}
		}
		
		return instance;
	}
	
	public void setValue(String key, Object value)
	{
		_cache.put(key, value);
	}
	
	public Object getValue(String key)
	{
		return _cache.get(key);
	}
}